package com.lijiayue.controller;

import com.lijiayue.model.domain.User;
import com.lijiayue.service.UserService;
import com.lijiayue.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@Slf4j
@Tag(name = "用户接口")
@RestController
@RequestMapping("/auth")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<Map<String, Object>> login(@RequestBody User user) {
        Result<Map<String, Object>> stringResult = userService.userLogin(user);
        return stringResult;
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<String> register(@RequestBody User user) throws InterruptedException {
        user.setCreateTime(new Date());
        userService.userRegister(user);
        return Result.ok("用户注册成功");
    }

}
